//
//  SessionMessage.m
//  BaiYing_Thinker
//
//  Created by 鹏 朱 on 15/10/22.
//  Copyright (c) 2015年 XKJH. All rights reserved.
//

#import "SessionMessage.h"
#import "SessonContentMessage.h"
#import "NSDate+Addition.h"
#import "AppDelegate.h"

@implementation SessionMessage

-(id)initWithSessonContentMessage:(SessonContentMessage *)message {
    
    if (self = [super init]) {
        
        _subject_id = message.subject_id;
        _session_id = kLocalSessionId;
        _update_time = [NSDate currentDateStringWithFormat:@"yyyy-MM-dd mm:HH:ss"];

//        if ([message.model isEqualToString:@"ASK"] || [message.model isEqualToString:@"SYSTEM"] || [message.sender isEqualToString:kAppDelegate.currentUser]) {
//            _session_id = kLocalSessionId;
//        }
        
        if ([message.isMyself isEqual: @1]) {
            
            //发送消息的session_id
            _session_id = kLocalSessionId;
            
        } else {
            
            //接收消息的session_id
            if ([message.model isEqualToString:@"SYSTEM"]) {
                _session_id = kLocalSessionId;
            } else {
                
                if (IsEmpty(message.recevier)) {
                    
                    if ([message.model isEqualToString:@"ASK"]) {
                        
                        //人问问题
                        _session_id = message.sender;
                        
                    } else {
                        //机器人发的应答消息
                        _session_id = kLocalSessionId;
                    }
                } else {
                    _session_id = message.sender;
                }
            }
        }
        
    }
    
    return self;
}

@end
